#include <iostream>

using ll = long long;

int const maxn = 100007;
int a[maxn];
ll tree[maxn * 8];
int one[maxn * 8];
ll cover[maxn * 8];

int n, m;

void push_up(int id, int l, int r)
{
    one[id] = one[id * 2] + one[id * 2 + 1];
    tree[id] = tree[id * 2] + tree[id * 2 + 1];
}

void push_down(int id, int l, int r)
{
    cover[id * 2] += cover[id];
    cover[id * 2 + 1] += cover[id];
    cover[id] = 0;
}

void build(int id, int l, int r)
{
    if (l == r) {
        cover[id] = 0;
        one[id] = a[l] == 1;
        tree[id] = a[l];
        return;
    }
    int mid = (l + r) / 2;
    build(id * 2, l, mid);
    build(id * 2 + 1, mid + 1, r);
    push_up(id, l, r);
}

ll query(int id, int l, int r, int tl, int tr)
{
    if (tl <= l && r <= tr) return tree[id] + cover[id];
    ll ret = 0;
    int mid = (l + r) / 2;
    push_down(id, l, r);
    if (tl <= mid) ret += query(id * 2, l, mid, tl, tr);
    if (tr > mid) ret += query(id * 2 + 1, mid + 1, r, tl, tr);
    return ret;
}

void update(int id, int l, int r, int tl, int tr, ll d)
{
    if (tl <= l && r <= tr) {
        cover[id] += d;
        if (one[id]) one[id] = 0;
        return;
    }
    int mid = (l + r) / 2;
    push_down(id, l, r);
    if (tl <= mid) update(id * 2, l, mid, tl, tr, d);
    if (tr > mid) update(id * 2 + 1, mid + 1, r, tl, tr, d);
    push_up(id, l, r);
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    int T; std::cin >> T;
    while (T--) {
        std::cin >> n >> m;
        for (int i = 1; i <= n; i++) std::cin >> a[i];
        build(1, 1, n);
        for (int i = 0; i < m; i++) {
            int opt, l, r, x;
            std::cin >> opt >> l >> r;
            if (opt == 1) {
                std::cin >> x;
                update(1, 1, n, l, r, x);
            } else if (opt == 2) {
                update_sqrt(1, 1, n, l, r);
            } else {
                std::cout << query(1, 1, n, l, r) << "\n";
            }
        }
    }
}

